from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.chrome.service import Service

import sys

sys.path.append(r'..')
from web_base.base_page import BasePage

class BaiduPage(BasePage):
    url = r'https://www.baidu.com/'
    # 搜索定位
    kw_loc = (By.ID, 'kw')
    su_loc = (By.ID, 'su')

    #登录定位
    login_btn_loc=(By.ID,'s-top-loginbtn')
    username_loc=(By.ID,'TANGRAM__PSP_11__userName')
    password_loc=(By.ID,'TANGRAM__PSP_11__password')
    isagree_loc=(By.ID,'TANGRAM__PSP_11__isAgree')
    login_submit_loc=(By.ID,'TANGRAM__PSP_11__submit')


    def __init__(self,driver):
        super().__init__(driver)
        self.get_url(self.url)

    def search(self,kw):
        self.ele_clear(self.kw_loc)
        self.input_ele(self.kw_loc,kw)
        self.ele_click(self.su_loc)
        sleep(3)

    def login(self,username,password):
        self.ele_click(self.login_btn_loc)
        sleep(3)
        self.ele_clear(self.username_loc)
        self.input_ele(self.username_loc,username)
        self.ele_clear(self.password_loc)
        self.input_ele(self.password_loc,password)
        self.ele_click(self.isagree_loc)
        self.ele_click(self.login_submit_loc)
        sleep(3)

    def hao123(self):
        pass

if __name__ == '__main__':
    kw='a6'
    username='123'
    password='456'

    chrome_location = r'D:\测试工具\Win_x64_1135105_chrome-win\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location
    driver_location = r'D:\测试工具\pythan\chromedriver.exe'
    service = Service(driver_location)
    driver = webdriver.Chrome(options=options, service=service)

    baidu_page=BaiduPage(driver)
    #测试搜索
    # baidu_page.search(kw)

    #测试登录
    baidu_page.login(username,password)
    driver.quit()
